package demo.feed4junit;

import org.databene.benerator.anno.Source;
import org.databene.feed4junit.Feeder;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import util.JsonUtils;
import util.TestUtil;

import java.util.Map;

@RunWith(Feeder.class)
public class DemoFeedTest {
    @Test
    @Source("Data.csv")//CSV source
    public void testMethod(int value1, int value2, int expected) {
        DemoFeed demoFeed = new DemoFeed();
        int actual = demoFeed.add(value1, value2);
        System.out.println("value1: " + value1 + " value2: " + value2 + " expected: " + expected + " actual: " + actual);
        Assert.assertEquals(expected, actual);
    }


    @Before
    public void init() throws Exception {
        String jsonInputStr = TestUtil.readFileString("/demo/feed4junit/demofeed/method1_inputObject.json");
        String jsonOutputStr = TestUtil.readFileString("/demo/feed4junit/demofeed/method1_outputObject.json");
        inputMap = JsonUtils.jsonToMap(jsonInputStr, InputObject.class);
        outputMap = JsonUtils.jsonToMap(jsonOutputStr, OutputObject.class);

    }

    Map<String, InputObject> inputMap;
    Map<String, OutputObject> outputMap;

    @Test
    @Source("Data2.csv")//CSV source
    public void testMethod1(String caseNum) {
        InputObject inputObject = inputMap.get(caseNum);
        DemoFeed demoFeed = new DemoFeed();
        OutputObject actual = demoFeed.method1(inputObject);
        OutputObject expect = outputMap.get(caseNum);
        System.out.println(caseNum + " expect: " + expect.getAge() + " actual: " + actual.getAge());
        Assert.assertEquals(expect.getAge(), actual.getAge());
    }
}
